
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>电子商务售前单</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="demo.css" rel="stylesheet" type="text/css" />
    <script src="scripts/boot.js" type="text/javascript"></script>
	<style>
	</style>
</head>
<body >
    <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
    buttons="#tabsButtons"
>
    <div title="列表" >
<div id="toolbar1" class="mini-toolbar" style="padding:2px;">
    <table style="width:100%;">
        <tr>
        <td style="width:100%;">
            <a class="mini-button" iconCls="icon-reload" plain="true" onclick="reload" >刷新</a>
            <a class="mini-button" iconCls="icon-download" plain="true" onclick="down">下载</a>
             <a class="mini-button" iconCls="icon-download" plain="true" onclick="promptClick">发送邮件</a>
             <span class="separator"></span>
        </td>
        
        </tr>
    </table>
</div>
    
   
   <div id="datagrid1" class="mini-datagrid" style="height:600px;width: 100%;" 
        url="/order/orderByItemCode" idField="id"
        allowResize="true" 
        allowCellEdit="true" allowCellSelect="true" multiSelect="true"
        allowCellValid="true" oncellvalidation="" showPager='false'  oncellclick='cellclick'
    >
    <div property="columns">
                   <div field="U_ItemCode" headeralign="center"  align="center"  width='34px'>物料代码</div>
                    <div field="U_ItemName" headeralign="center"  align="center" >物料名称</div>
                   <div field="ct" align="center" headeralign="center" width='20px'> 数量</div>                            
                   <div field="AX_lastvandor" name="company" headeralign="center" width='8%'  align="center">推荐供应商</div>
        </div>
    
    </div>
    </div>
 
</div>

</body>
<script type="text/javascript">
		function reload(){
			grid.load();
	   }

		   function down(){
			   var rows = grid.getSelecteds();
			   var itemCodes = '';
			   var len = rows.length;
			   if(len<1){
					mini.alert('至少选中一行');
					return ;
				   }
			   for(var i=0;i<len;i++){
				   itemCodes+=rows[i].U_ItemCode+',';
				   }

			   window.open('/order/down?codes='+itemCodes);


				 }
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.load();
  
        function search(){
			  mini.mask({
	               el: document.body,
	               cls: 'mini-mask-loading',
	               html: '数据加载中....'
	           }); 
	            
      	  $.ajax({
              url: "/order/orderByItemCode",
              type: "post",
              dataType:'json',
              success: function (data) {
            	  
            		if(data==false){
     					 mini.unmask(document.body);
     					 mini.alert('没有找到记录');
     					 }
          		    grid.setData(data);
   				    mini.unmask(document.body);
              },
              error: function (jqXHR, textStatus, errorThrown) {
                  alert(jqXHR.responseText);
              }
          });

            }

        function cellclick(e){
            //e = e.record;
      		
       	 	column = e.column,
        	 field =  e.column.field,
       	     value = e.record.AX_lastvandor;
     	    
          	 if (field == "AX_lastvandor") {
          		 var len = grid.data.length;
          		 var data = grid.data;
          		 for(var i=0;i<len;i++){
              		 if(data[i].AX_lastvandor==value){
    						grid.setSelected (i+1);
                  		 }
              		 }
             }
            }
        

    

    	jQuery('.showCellTooltip').live('click',function(){
      		 var name = jQuery(this).html();
      		 var len = grid.data.length;
      		 var data = grid.data;
      		 for(var i=0;i<len;i++){
          		 if(data[i].AX_lastvandor==name){
						grid.setSelected (i+1);
              		 }
          		 }
      		
      	 })
            

        grid.on("load", function () {
            grid.mergeColumns(["company"]);
        });

        grid.load()
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var U_ItemCode = record.U_ItemCode;
            var rowIndex = e.rowIndex;

            var s = '<a class="Edit_Button" href="javascript:editRow(\'' + U_ItemCode + '\')" >下载订单</a>&nbsp;&nbsp;&nbsp;'
                    + ' <a class="Edit_Button" href="javascript:editRow(\'' + U_ItemCode + '\')" >发送至供应商</a>'
                  
            return s;
        }


        

        function promptClick() {

       	 var rows = grid.getSelecteds();
       	 var name = rows[0].U_ItemCode;
       	 $.ajax({
             
             url: "/order/getEmail",
             data:{name:name},
             type: "post",
           
             success: function (data) {
            	 mini.showMessageBox({
                     width: 250,
                     title: "发送邮件",
                     buttons: ["发送", "cancel"],
                     message: "自定义Html",
                     html: "邮箱:<input type='mini-textbox' id='email' value='"+data+"'>",
                     showModal: false,
                     callback: function (action) {
                         if(action=='发送'){
                        	 sendEmail(jQuery('#email').val());
                        	 }
                       
                     }
                 });
           	
         		    
  				    
             },
             error: function (jqXHR, textStatus, errorThrown) {
                 alert(jqXHR.responseText);
             }
         });
  
        }

        function sendEmail(email){
			
      	  var rows = grid.getSelecteds();
		   var itemCodes = '';
		   var len = rows.length;
		   if(len<1){
				mini.alert('至少选中一行');
				return ;
			   }

		   if(email==''){
				mini.alert('邮箱不能为空');
				return ;
			}
		   for(var i=0;i<len;i++){
			   itemCodes+=rows[i].U_ItemCode+',';
			   }
		   
       	 mini.mask({
             el: document.body,
             cls: 'mini-mask-loading',
             html: '邮件发送中....'
         });



         $.ajax({
             
             url: "/order/down",
             data:{codes:itemCodes,type:1,tomail:email},
             type: "post",
             dataType:'json',
             success: function (data) {
           	  
           		if(data.code==0){
    					 mini.unmask(document.body);
    					 mini.alert(data.msg);
    					 }
				 		else
        				 {
    					 mini.alert(data.msg);
    					 mini.unmask(document.body);
        				 }
         		    
  				    
             },
             error: function (jqXHR, textStatus, errorThrown) {
                 alert(jqXHR.responseText);
             }
         });

         }
    </script>

</html>